package com.web.manager.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.web.manager.pojo.Court;
import com.web.manager.pojo.Major;
import com.web.manager.mapper.CourtMapper;
import com.web.manager.mapper.MajorMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class MajorService extends ServiceImpl<MajorMapper, Major> {
    @Resource
    private MajorMapper majorMapper;

    @Resource
    private CourtMapper courtMapper;

    @Override
    public boolean save(Major entity){

        int a  = majorMapper.selectType(entity.getBelong());
        Court court = courtMapper.selectType2(entity.getBelong());
        court.setNum(a+1);
        courtMapper.updateById(court);
        return super.save(entity);
    }


    public Major selectByUsername(String name){
        QueryWrapper<Major> queryWrapper = new QueryWrapper<>(); //条件查询器
        queryWrapper.eq("name",name);  // ==> where username = #{username}


        // 根据用户名查询数据库的用户信息
        return  this.getOne(queryWrapper); // ==>select * from manager_user where username = #{username}
    }

    public Major getByMajorid(Integer majorid) {
        return majorMapper.selectByMajorid(majorid);
    }
}
